//
//  CNBottomBar.m
//  CsdnPlus
//
//  Created by 孟瑞瑞 on 2018/7/11.
//  Copyright © 2018年 CSDN. All rights reserved.
//

#import "CNBottomBar.h"
#import "UIButton+CNExtension.h"
#import "CNViewConst.h"
#import <HXPhotoPicker/HXPhotoPicker.h>

#define TextViewHeight 30

@interface CNBottomBar ()<CNCommentToolbarDelegate>
@property (nonatomic, strong, readwrite) PPStickerTextView *textView;
@property (nonatomic, strong) UIButton *diggBtn;//点赞
@property (nonatomic, strong) UIButton *collectionBtn;//收藏
@property (nonatomic, strong) UIButton *shareBtn;//分享
@property (nonatomic, strong) UILabel *dynamicCommentLb;
@property (nonatomic, strong) UILabel *diggCountLb;
@property (nonatomic, strong) UILabel *diggLabel;
@property (nonatomic, strong) UILabel *shareLabel;
@property (nonatomic, strong) UILabel *collectionLabel;
@property (nonatomic, strong) UIView *commentView;
@property (nonatomic, strong) UILabel *commentCountLabel;
@property (nonatomic, strong) UILabel *commentCountLb;
@property (nonatomic, assign) BOOL bottomIsA;
@end

@implementation CNBottomBar

- (instancetype)init{
    self = [super init];
    if(self){
        self.bottomIsA = [CNViewConst blogBottomShowAB];
        [self setupUI];
    }
    return self;
}

- (instancetype)initWithBarType:(CNBottomBarType)barType{
    self = [super init];
    if(self){
        self.barType = barType;
        self.bottomIsA = [CNViewConst blogBottomShowAB];
        [self setupUI];
    }
    return self;
}

#pragma mark -- 设置UI

- (void)setupUI
{
    self.lineView.hidden = NO;
    if(self.barType == CNBottomBarTypeBlogComment)
    {
        self.diggBtn.hidden = NO;
        self.commentView.hidden = NO;
        self.textView.hidden = NO;
        self.dynamicCommentLb.hidden = YES;

    }
    else if(self.barType == CNBottomBarTypeBBSComment)
    {
        self.diggBtn.hidden = YES;
        self.commentView.hidden = YES;
        self.textView.hidden = NO;
        self.dynamicCommentLb.hidden = YES;

    }else if (self.barType == CNBottomBarTypeBlinComment){
        self.diggBtn.hidden = YES;
        self.commentView.hidden = YES;
        self.collectionBtn.hidden = YES;
        self.shareBtn.hidden = YES;
        self.textView.hidden = NO;
        self.dynamicCommentLb.hidden = YES;

    }else if (self.barType == CNBottomBarTypeBlogCommentDetail){
        self.diggBtn.hidden = YES;
        self.commentView.hidden = YES;
        self.shareBtn.hidden = YES;
        self.textView.hidden = NO;
        self.dynamicCommentLb.hidden = NO;
    }
    

}


#pragma mark -- 显示键盘
- (void)showKeyboardView{
    if ([CNViewConst isLogin])
    {
        self.toolBar.textView.placeholder = @"写评论";
        //[self.toolBar showKeyBoard];
    }
    if(self.delegate && [self.delegate respondsToSelector:@selector(didClickCommentTextView)]){
        [self.delegate didClickCommentTextView];
    }
}

#pragma mark -- 显示键盘
- (void)showKeyboardViewWithText:(NSString *)text
{
    if ([CNViewConst isLogin])
    {
        self.toolBar.textView.placeholder = text;
        [self.toolBar showKeyBoard];
    }
    else
    {
        if(self.delegate && [self.delegate respondsToSelector:@selector(didClickCommentTextView)]){
            [self.delegate didClickCommentTextView];
        }
    }
}
#pragma mark --点赞动画
- (void)addDigAnimation{
    [self.diggBtn addDiggButtonAnimationWihtLineColor:[UIColor colorFromHexCode:@"d92e2e"] isRote:NO];
}
#pragma mark -- 点击评论视图
- (void)commentViewClick{
    if(self.delegate && [self.delegate respondsToSelector:@selector(showCommentView)]){
        [self.delegate showCommentView];
    }
}

#pragma mark -- lazy load
-(PPStickerTextView *)textView
{
    if(!_textView)
    {
        if (self.barType == CNBottomBarTypeBlogComment) {
            _textView = [[PPStickerTextView alloc]initWithIsBlog:YES];
        } else {
            _textView = [[PPStickerTextView alloc]init];
        }
        _textView.theme_backgroundColor = newSearchBarBGPickerColor;
        _textView.placeholder = @"写评论";
        _textView.scrollEnabled = NO ;
        _textView.editable = NO ;
        _textView.autocapitalizationType = UITextAutocapitalizationTypeNone;
        _textView.showsVerticalScrollIndicator = YES;
        if ([CNThemesManager isNight])
        {
//            _textView.placeholderColor = commentPlaceholderNightTextColor;
            _textView.layer.borderColor = [UIColor clearColor].CGColor;
        }
        else
        {
//            _textView.placeholderColor = commentPlaceholderTextColor;
            _textView.layer.borderColor = [UIColor clearColor].CGColor;
        }
        _textView.placeholderColor = cellDesTitleTextColor;
        _textView.theme_textColor = cellTitleTextColorPicker;
        _textView.scrollsToTop = NO;
        _textView.returnKeyType = UIReturnKeyDefault;
        _textView.enablesReturnKeyAutomatically = YES;
        if (@available(iOS 11.0, *)) {
            _textView.textDragInteraction.enabled = NO;
        }
        _textView.font = [UIFont systemFontOfSize:14];
//        _textView.theme_tintColor = cellTitleTextColorPicker;
        _textView.textContainerInset = UIEdgeInsetsMake(8,8,8,8);
        if (iPhone4 || iPhone5)
        {
            _textView.textContainerInset = UIEdgeInsetsMake(5,8,0,8);
        }
        if (!self.bottomIsA&&self.barType==CNBottomBarTypeBlogComment) {
            _textView.layer.cornerRadius = 17;
        } else {
            _textView.layer.cornerRadius = 8;
            
        }
        _textView.layer.borderWidth = 0.5;
        _textView.layer.masksToBounds = YES ;
        @weakify(self);
        [_textView addTapGestureWithBlock:^(UIView *gestureView) {
            @strongify(self);
            [self showKeyboardView];
        }];
        
        [self addSubview:_textView];
        [_textView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(8);
            make.bottom.mas_equalTo(-8);
            make.centerY.mas_equalTo(0);
            if (!self.bottomIsA&&self.barType==CNBottomBarTypeBlogComment) {
                make.height.mas_equalTo(48);
            } else {
                make.height.mas_equalTo(34);
            }
            
            if (self.barType == CNBottomBarTypeBlogComment)
            {
                make.left.mas_equalTo(16);
                if (self.bottomIsA) {
                    make.right.mas_equalTo(self.commentView.mas_left).mas_equalTo(-16);
                } else {
                    make.width.mas_equalTo(117);
                }
            }
            else if (self.barType == CNBottomBarTypeBBSComment)
            {
                make.left.mas_equalTo(16);
                make.right.mas_equalTo(self.collectionBtn.mas_left).mas_equalTo(-16);
            }else if (self.barType == CNBottomBarTypeBlinComment){
                make.left.mas_equalTo(16);
                make.right.mas_equalTo(-16);
            }else if (self.barType == CNBottomBarTypeBlogCommentDetail){
                make.left.mas_equalTo(16);
                make.right.mas_equalTo(self.dynamicCommentLb.mas_left).offset(-16);
            }
        }];
    }
    return _textView;
}
// 评论
- (UIView *)commentView{
    if (!_commentView) {
        if (!self.bottomIsA&&self.barType==CNBottomBarTypeBlogComment) {
            // 评论 B
            UIButton *commentView = [UIButton buttonWithType:(UIButtonTypeCustom)];
            [commentView theme_setImage:commentBarImage forState:UIControlStateNormal];
            [self addSubview:commentView];
            _commentView = commentView;
            [commentView setEnlargeEdgeWithTop:0 right:0 bottom:8 left:0];
            [commentView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.right.mas_equalTo(self.collectionBtn.mas_left).offset(-30);
                make.size.mas_equalTo(CGSizeMake(24, 24));
                make.centerY.mas_equalTo(self.shareBtn);
            }];

            UILabel *commentCountLabel = [[UILabel alloc]init];
            commentCountLabel.textAlignment = NSTextAlignmentCenter;
            commentCountLabel.backgroundColor = [UIColor colorWithHexString:@"#E33E33"];
            commentCountLabel.textColor = [UIColor colorWithHexString:@"#FFFFFF"];
            commentCountLabel.font = [UIFont systemFontOfSize:10];
            commentCountLabel.layer.borderColor = [UIColor colorWithHexString:@"#FFFFFF"].CGColor;
            commentCountLabel.layer.borderWidth = 1;
            commentCountLabel.layer.cornerRadius = 7.5;
            commentCountLabel.layer.masksToBounds = YES;
            [commentView addSubview:commentCountLabel];
            self.commentCountLabel = commentCountLabel;
            [commentCountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.mas_equalTo(10);
                make.top.mas_equalTo(-4);
                make.height.mas_equalTo(15);
                make.width.mas_equalTo(0);
            }];
            @weakify(self);
            [commentView bk_addEventHandler:^(id sender) {
                @strongify(self);
                [self commentViewClick];
            } forControlEvents:(UIControlEventTouchUpInside)];
            if (!self.bottomIsA) {
                UILabel *commentLabel = [[UILabel alloc]init];
                commentLabel.text = @"评论";
                commentLabel.theme_textColor = [ThemeColorPicker pickerWithColors:@[@"#555666", @"#CCCCD8"]];
                commentLabel.font = [UIFont systemFontOfSize:11];
                [self addSubview:commentLabel];
                [commentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.centerX.mas_equalTo(commentView);
                    make.bottom.mas_equalTo(self.shareLabel);
                }];
            }
        } else {
            // 评论 A
            _commentView = [[UIView alloc]init];
            [self addSubview:_commentView];
            [_commentView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.right.mas_equalTo(self.collectionBtn.mas_left).offset(-16);
                make.size.mas_equalTo(CGSizeMake(24, 24));
                make.centerY.mas_equalTo(0);
            }];
            UILabel *comment = [[UILabel alloc]init];
            comment.text = @"评论";
            comment.font = [UIFont systemFontOfSize:11];
            comment.theme_textColor = newCommentTextColorPicker;
            comment.textAlignment = NSTextAlignmentCenter;
            [_commentView addSubview:comment];
            [comment mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.left.right.mas_equalTo(self.commentView);
                make.height.mas_equalTo(13);
            }];
            @weakify(self);
            [_commentView addTapGestureWithBlock:^(UIView *gestureView) {
                @strongify(self);
                [self commentViewClick];
            }];
        }
     }
    return _commentView;
}

- (UILabel *)commentCountLb{
    if (!_commentCountLb) {
        _commentCountLb = [[UILabel alloc]init];
        _commentCountLb.textAlignment = NSTextAlignmentCenter;
        _commentCountLb.textColor = [UIColor colorFromHexCode:@"#E33E33"];
        _commentCountLb.font = [UIFont systemFontOfSize:10];
        [self.commentView addSubview:_commentCountLb];
        [_commentCountLb mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.left.right.mas_equalTo(self.commentView);
        }];
    }
    return _commentCountLb;
}

- (UILabel *)dynamicCommentLb{
    if (!_dynamicCommentLb) {
        _dynamicCommentLb = [[UILabel alloc]init];
        [self addSubview:_dynamicCommentLb];
        _dynamicCommentLb.text = @"发送";
        _dynamicCommentLb.textColor = [UIColor colorFromHexCode:@"#999AAA"];
        _dynamicCommentLb.font = [UIFont systemFontOfSize:14];
        [_dynamicCommentLb mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(-16);
            make.centerY.mas_equalTo(0);
            make.height.mas_equalTo(self);
        }];
    }
    return _dynamicCommentLb;
}
// 分享
- (UIButton *)shareBtn
{
    if (!_shareBtn) {
        _shareBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
        [_shareBtn theme_setImage:shareToolBarImage forState:(UIControlStateNormal)];
        [_shareBtn theme_setImage:shareToolBarImage forState:(UIControlStateHighlighted)];
        [self addSubview:_shareBtn];
        [_shareBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(-16);
            if (!self.bottomIsA&&self.barType==CNBottomBarTypeBlogComment) {
                
                make.top.mas_equalTo(5);
            } else {
                make.centerY.mas_equalTo(0);
            }
            make.size.mas_equalTo(CGSizeMake(24, 24));
        }];
//        if (self.bottomIsA) {
//            [_shareBtn setEnlargeEdge:8];
//        } else {
//            [_shareBtn setEnlargeEdgeWithTop:0 right:0 bottom:8 left:0];
//        }
        
        @weakify(self);
        [_shareBtn bk_addEventHandler:^(id sender) {
            @strongify(self);
            if (self.delegate && [self.delegate respondsToSelector:@selector(didClickShareBtn)])
            {
                [self.delegate didClickShareBtn];
            }
        } forControlEvents:(UIControlEventTouchUpInside)];
        if (!self.bottomIsA&&self.barType==CNBottomBarTypeBlogComment) {
            UILabel *shareLabel = [[UILabel alloc]init];
            shareLabel.text = @"分享";
            shareLabel.theme_textColor = [ThemeColorPicker pickerWithColors:@[@"#555666", @"#CCCCD8"]];
            shareLabel.font = [UIFont systemFontOfSize:11];
            [self addSubview:shareLabel];
            [shareLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                make.centerX.mas_equalTo(_shareBtn);
                make.bottom.mas_equalTo(-4);
            }];
            self.shareLabel = shareLabel;
        }
    }
    return _shareBtn;
}
// 收藏
-(UIButton *)collectionBtn
{
    if (!_collectionBtn) {
        _collectionBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
        [_collectionBtn theme_setImage:collectionImage forState:UIControlStateNormal];
        [_collectionBtn theme_setImage:collectionImage forState:UIControlStateHighlighted];
        [self addSubview:_collectionBtn];
        if (!self.bottomIsA&&self.barType==CNBottomBarTypeBlogComment) {
            [_collectionBtn setEnlargeEdgeWithTop:0 right:0 bottom:8 left:0];
        } else {
            [_collectionBtn setEnlargeEdge:8];
            
        }
        [_collectionBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            if (self.barType == CNBottomBarTypeBBSComment) {
                make.centerY.mas_equalTo(0);
                make.right.mas_equalTo(self.shareBtn.mas_left).mas_equalTo(-16);
            } else {
                if (!self.bottomIsA&&self.barType==CNBottomBarTypeBlogComment) {
                    make.centerY.mas_equalTo(self.shareBtn);
                    make.right.mas_equalTo(self.diggBtn.mas_left).mas_equalTo(-30);
                } else {
                    make.centerY.mas_equalTo(0);
                    make.right.mas_equalTo(self.diggBtn.mas_left).mas_equalTo(-16);
                }
            }
            make.size.mas_equalTo(CGSizeMake(24, 24));
        }];

        @weakify(self);
        [_collectionBtn bk_addEventHandler:^(id sender) {
            @strongify(self);
            if (self.delegate && [self.delegate respondsToSelector:@selector(didClickCollectionBtn)]) {
                [self.delegate didClickCollectionBtn];
            }
        } forControlEvents:(UIControlEventTouchUpInside)];
        if (!self.bottomIsA&&self.barType==CNBottomBarTypeBlogComment) {
            UILabel *collectionLabel = [[UILabel alloc]init];
            collectionLabel.text = @"收藏";
            collectionLabel.theme_textColor = [ThemeColorPicker pickerWithColors:@[@"#555666", @"#CCCCD8"]];
            collectionLabel.font = [UIFont systemFontOfSize:11];
            [self addSubview:collectionLabel];
            [collectionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                make.centerX.mas_equalTo(_collectionBtn);
                make.bottom.mas_equalTo(self.shareLabel);
            }];
            self.collectionLabel = collectionLabel;
        }
    }
    return _collectionBtn;
}

// 点赞
- (UIButton *)diggBtn
{
    if (!_diggBtn) {
        _diggBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
        [_diggBtn theme_setImage:blogZanImage forState:UIControlStateNormal];
        [_diggBtn theme_setImage:blogZanImage forState:UIControlStateHighlighted];
        [self addSubview:_diggBtn];
        if (!self.bottomIsA&&self.barType==CNBottomBarTypeBlogComment) {
            [_diggBtn setEnlargeEdgeWithTop:0 right:0 bottom:8 left:0];
        } else {
            [_diggBtn setEnlargeEdge:15];
        }
        [_diggBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            if (!self.bottomIsA&&self.barType==CNBottomBarTypeBlogComment) {
                make.right.mas_equalTo(self.shareBtn.mas_left).mas_equalTo(-30);
                make.centerY.mas_equalTo(self.shareBtn);
            } else {
                make.right.mas_equalTo(self.shareBtn.mas_left).mas_equalTo(-16);
                make.centerY.mas_equalTo(0);
            }
            make.size.mas_equalTo(CGSizeMake(24, 24));
        }];
        @weakify(self);
        [_diggBtn bk_addEventHandler:^(id sender) {
            @strongify(self);
            if (self.delegate && [self.delegate respondsToSelector:@selector(didClickDiggBtn)])
            {
                [self.delegate didClickDiggBtn];
            }
        } forControlEvents:(UIControlEventTouchUpInside)];
        if (!self.bottomIsA&&self.barType==CNBottomBarTypeBlogComment) {
            UILabel *diggLabel = [[UILabel alloc]init];
            diggLabel.text = @"点赞";
            diggLabel.theme_textColor = [ThemeColorPicker pickerWithColors:@[@"#555666", @"#CCCCD8"]];
            diggLabel.font = [UIFont systemFontOfSize:11];
            [self addSubview:diggLabel];
            [diggLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                make.centerX.mas_equalTo(_diggBtn);
                make.bottom.mas_equalTo(self.shareLabel);
            }];
            self.diggLabel = diggLabel;
        }
    }
    return _diggBtn;
}

-(void)setIsDigg:(BOOL)isDigg {
    _isDigg = isDigg;
    if (!isDigg) {
        [_diggBtn theme_setImage:blogZanImage forState:UIControlStateNormal];
        [_diggBtn theme_setImage:blogZanImage forState:UIControlStateHighlighted];
        if (!self.bottomIsA&&self.barType==CNBottomBarTypeBlogComment) {
            self.diggLabel.text = @"点赞";
        }
    }else{
        [_diggBtn theme_setImage:blogZanSelectImage forState:UIControlStateNormal];
        [_diggBtn theme_setImage:blogZanSelectImage forState:UIControlStateHighlighted];
        if (!self.bottomIsA&&self.barType==CNBottomBarTypeBlogComment) {
            self.diggLabel.text = @"已点赞";
        }
    }
}

-(void)setIsMe:(BOOL)isMe
{
    _isMe = isMe;
    if (isMe) {
        self.collectionBtn.hidden = YES;
        self.collectionLabel.hidden = YES;
        self.collectionBtn.userInteractionEnabled = NO;
        [self.collectionBtn mas_updateConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(0, 0));
        }];
        [self.commentView mas_updateConstraints:^(MASConstraintMaker *make) {
            if (!self.bottomIsA&&self.barType==CNBottomBarTypeBlogComment) {
                make.right.mas_equalTo(self.diggBtn.mas_left).mas_equalTo(-30);
            } else {
                make.right.mas_equalTo(self.diggBtn.mas_left).mas_equalTo(-16);
                
            }

        }];
    }
}

-(void)setIsPrivacy:(BOOL)isPrivacy
{
    _isPrivacy = isPrivacy;
    if (!isPrivacy) {
        self.shareBtn.hidden = NO;
        [_diggBtn mas_updateConstraints:^(MASConstraintMaker *make) {
            if (!self.bottomIsA&&self.barType==CNBottomBarTypeBlogComment) {
                make.right.mas_equalTo(self.shareBtn.mas_left).mas_equalTo(-30);
            } else {
                make.right.mas_equalTo(self.shareBtn.mas_left).mas_equalTo(-16);
                
            }
        }];
    } else {
        self.shareBtn.hidden = YES;
        [_diggBtn mas_updateConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(-16);
        }];
    }
}

-(void)setIsCollection:(BOOL)isCollection
{
    _isCollection = isCollection;
    if (!isCollection)
    {
        [_collectionBtn theme_setImage:collectionImage forState:UIControlStateNormal];
        [_collectionBtn theme_setImage:collectionImage forState:UIControlStateHighlighted];
        if (!self.bottomIsA&&self.barType==CNBottomBarTypeBlogComment) {
            self.collectionLabel.text = @"收藏";
        }
    } else {
        if (!self.bottomIsA&&self.barType==CNBottomBarTypeBlogComment) {
            [_collectionBtn theme_setImage:collectionSelectImageB forState:UIControlStateNormal];
            [_collectionBtn theme_setImage:collectionSelectImageB forState:UIControlStateHighlighted];
            self.collectionLabel.text = @"已收藏";
        } else {
            [_collectionBtn theme_setImage:collectionSelectImageA forState:UIControlStateNormal];
            [_collectionBtn theme_setImage:collectionSelectImageA forState:UIControlStateHighlighted];
        }
    }
}

-(void)setDiggCount:(NSString *)diggCount {
    _diggCount = diggCount;
    if (!self.bottomIsA&&self.barType==CNBottomBarTypeBlogComment) {
        self.diggLabel.text = @"已点赞";
    }
}

-(UILabel *)diggCountLb
{
    if (!_diggCountLb) {
        _diggCountLb = [[UILabel alloc]init];
        _diggCountLb.theme_backgroundColor = blogZanLabelTextColorPicker;
        _diggCountLb.theme_textColor = naviBGColorPicker;
        _diggCountLb.layer.masksToBounds = YES;
        _diggCountLb.layer.cornerRadius = 7;
        _diggCountLb.textAlignment = NSTextAlignmentCenter;
        _diggCountLb.font = [UIFont systemFontOfSize:10];
        [self addSubview:_diggCountLb];
        [_diggCountLb mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(3);
            make.left.mas_equalTo(self.diggBtn.mas_right).mas_equalTo(0);
            make.height.mas_equalTo(15);
            make.width.mas_greaterThanOrEqualTo(18);
        }];
    }
    return _diggCountLb;
}

-(void)setCommentCount:(NSString *)commentCount {
    _commentCount = commentCount;
    if (!self.bottomIsA&&self.barType==CNBottomBarTypeBlogComment) {
        _commentCountLb.hidden = YES;
        _commentCountLabel.text = commentCount;
        if ([commentCount isEqualToString:@"0"]) {
            _commentCountLabel.hidden = YES;
        } else {
            _commentCountLabel.hidden = NO;
            CGFloat w = [self.commentCountLabel hx_getTextWidth] + 10;
            [_commentCountLabel mas_updateConstraints:^(MASConstraintMaker *make) {
                make.width.mas_equalTo(w);
            }];
        }
    } else {
        if ([commentCount isEqualToString:@"0"]) {
            _commentCountLb.hidden = YES;
        }else{
            _commentCountLb.hidden = NO;
        }
        self.commentCountLb.text = commentCount;
    }
}

-(UIView *)lineView
{
    if (!_lineView) {
        _lineView = [[UIView alloc]init];
        _lineView.backgroundColor = [CNThemesManager isNight]? [UIColor colorFromHexCode:@"#f0f0f5" andAlpha:0.2] : [UIColor colorFromHexCode:@"#151517" andAlpha:0.2];
        [self addSubview:_lineView];
        [_lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.mas_equalTo(0);
            make.height.mas_equalTo(0.25);
            make.top.mas_equalTo(0);
        }];
    }
    return _lineView;
}

-(CNCommentToolbar *)toolBar
{
    if (!_toolBar) {
        _toolBar = [[CNCommentToolbar alloc]init];
        _toolBar.delegate = self;
    }
    return _toolBar;
}

#pragma mark - CNCommentToolbarDelegate
- (void)commentToolbarDidClinkAtButton:(CNCommentToolbar *)commentToolbar{
    if (self.barType == CNBottomBarTypeBlinComment){
        if(self.delegate && [self.delegate respondsToSelector:@selector(didClickAtButton)]){
            [self.delegate didClickAtButton];
        }
    }
}
-(void)commentToolbarDidClickSendButton:(CNCommentToolbar *)commentToolbar
{
    NSString *plainText = commentToolbar.plainText;
    if (!plainText.length) {
        return;
    }

    if (self.barType == CNBottomBarTypeBlogComment || self.barType == CNBottomBarTypeBlogCommentDetail)
    {
        if(self.delegate && [self.delegate respondsToSelector:@selector(sendCommentWidthText:PostId:IndexPath:ParentIndexPath:TableView:)]){
            [self.delegate sendCommentWidthText:plainText PostId:self.postId IndexPath:self.indexPath ParentIndexPath:self.parentIndexPath TableView:self.subTableView];
        }

    }
    else if (self.barType == CNBottomBarTypeBBSComment)
    {
        if(self.delegate && [self.delegate respondsToSelector:@selector(sendCommentWidthText:PostId:IndexPath:)]){
            [self.delegate sendCommentWidthText:plainText PostId:self.postId IndexPath:self.indexPath];
        }

    }else if (self.barType == CNBottomBarTypeBlinComment){
        if(self.delegate && [self.delegate respondsToSelector:@selector(sendCommentWithText:itemId:commentId:replyUsername:IndexPath:ParentIndexPath:TableView:)]){
            [self.delegate sendCommentWithText:plainText itemId:self.postId commentId:self.commentId replyUsername:self.replyUserName IndexPath:self.indexPath ParentIndexPath:self.parentIndexPath TableView:self.subTableView];
        }
    }
    if(self.barType != CNBottomBarTypeBlinComment){
        [commentToolbar clearText];

    }


}

-(void)dealloc
{

    [_toolBar removeFromSuperview];
    self.toolBar = nil;
}

@end
